%from datetime import datetime
%import hashlib
%from datamodel import Reply, Account
%from helper import PrettyDate
%from google.appengine.api import users

%date = datetime.strptime(str(article.key.id())[:-5], "%Y%m%d%H%M")
<article> <!--article start-->
<header>
  <h1 class="entry-title">{{article.title}}</h1>
  <p class="meta">
    <time datetime="{{date.strftime('%Y-%m-%dT%H:%M:%SZ')}}" pubdate data-updated="true"> {{date.strftime('%b')}}
      {{"%s%s"%(date.day, 'trnshddt'[0xc0006c000000006c>>2*date.day&3::4])}}, {{date.year}}</time> &bull;
    {{', '.join(article.categories)}} &bull; tags: {{', '.join(article.tags)}} &bull; {{article.language}} &bull;
    {{!'%s only &bull; '%article.purview if article.purview != 'anonymous' else ''}}{{article.counter}} hits,
    {{Reply.query(ancestor=article.key).count()}} reply
  </p>
</header>

<div class="entry-content">
<p>{{!article.summary}}</p>
{{!article.body}}
</div>
</article> <!--article stop-->

<a name="comments"><br></a>

%if month_list:
<section>
  <h1 class="topline">Comments</h1>
  <div id="comments" class="comments">
    <ul class="singlecomments" id="commentlist">
  %cur_user = users.get_current_user()
  %is_admin = True if users.is_current_user_admin() else False
  %for i in replies:
    %author = Account.get_by_id(i.author_key.id())
    %is_cur_user = True if (cur_user and cur_user.email() == i.author_key.id()) else False
    %if not (i.approval or is_cur_user or is_admin):
      %continue
    %end
    %gravatar_url = "http://www.gravatar.com/avatar/" + hashlib.md5(author.key.id().lower().split('*')[0]).hexdigest() + "?s=48"
      <li>
        <div>
          <img alt='' src="{{gravatar_url}}" class='avatar' height='48' width='48' />
          <div class="fl">
	    <em class="grey">{{PrettyDate(i.key.id())}}</em>
    %if author.site:
            <a href='{{author.site}}' target="_blank" rel="nofollow">{{author.nickname}}</a>
    %else:
            {{author.nickname}}
    %end
            <span class="grey">says:</span>  <br/>
          </div>
    %if not i.approval:
          waiting for approval
    %end
    %if is_admin:
	  <form action="/admin/approval" method="POST">
	    <input type="hidden" name="article" value="{{article.key.id()}}">
	    <input type="hidden" name="reply" value="{{i.key.id()}}">
	    <input type="submit" name="approval" value="delete">
	    <input type="submit" name="approval" value="edit">
      %if not i.approval:
	    <input type="submit" name="approval" value="approve">
      %end
	  </form>
      usr_id: {{author.key.id()}}, <a href=/admin/edit_account/{{author.key.id()}}>edit</a>
    %end
        </div>
        <p>{{!i.body}}</p>
      </li>
  %end
    </ul>
  </div>
  %if len(month_list) > 1:
  <div class="pagination">
    <a class="prev" href="?">&uarr; First</a>
    <span style="color:#ccc">2012 &larr; &nbsp;</span>
    %for i in month_list:
    <a href="?date={{i[0][0]}}.{{i[0][1]}}~{{i[1][0]}}.{{i[1][1]}}" {{!'style="color:#222"' if i[2] else ''}}
      %if i[0][1] != i[1][1]:
        title="{{i[0][0]}}.{{i[0][1]}}~{{i[1][0]}}.{{i[1][1]}}">{{i[0][1]}}~{{i[1][1]}}
      %else:
        title="{{i[0][0]}}.{{i[0][1]}}">{{i[0][1]}}
      %end
    </a>
    %end
    <span style="color:#ccc">&nbsp; &rarr; 2010</span>
    <a class="next" href="?date={{month_list[-1][1][0]}}.{{month_list[-1][1][1]}}">Last &darr;</a>
  </div>
  %end
</section>
%end

<!-- new comment -->
<section>
  <div id="respond" class="topline">
    <h2 class="respond">Leave a Comment</h2>
    <form action="" method="post">
%if not sidebar['account']:
      Recommend login to use.
      <table>
      <tr><th>Name:</th><td><input type="text" name="name" />*</td></tr>
      <tr><th>Email:</th><td><input type="email" name="email" />*</td></tr>
      <tr><th>Site:</th><td><input type="url" name="site" /></td></tr>
      </table>
%end
<textarea name="comment" id="markItUp" spellcheck="false">
&lt;pre&gt;
put your comment here...
&lt;/pre&gt;

Tips: full html tags are supported, you can preview before submit...
</textarea>
      <p>
	<input name="submit" class="submit" type="submit" tabindex="5" value="Submit Comment" /> 
      </p>
    </form>
    <script type="text/javascript">
      $(function() { $('#markItUp').markItUp(mySettings); });
    </script>
  </div>
</section>
<!-- new comment end -->

%rebase templates/layout_main sidebar=sidebar
